{extend name="layout:base" /}
{block name="main_content"}
  <div class="page-content">
    <!--主题-->
    <?php if(!empty($current_page)): ?>
      <div class="page-header">
        <h1>
          您当前操作
          <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
            {$current_page.title|default=''}
          </small>
        </h1>
      </div>
    <?php endif; ?>
    <div class="row">
      <?php if(!empty($notice)): ?>
        <div class="alert alert-block alert-success">
          <button type="button" class="close" data-dismiss="alert">
            <i class="ace-icon fa fa-times"></i>
          </button>
          <i class="ace-icon fa fa-check green"></i>
          {$notice}
        </div>
      <?php endif; ?>
      <div class="col-xs-12">
        <form id="settings-form" class="form-horizontal" method="post">
          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 
              是否开启邮箱：
            </label>
            <div class="col-sm-9" style="padding-top:5px;">
              <input name="options[smtp_open]" id="smtp_open" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" <?php if(isset($options["smtp_open"]) && intval($options["smtp_open"]) > 0){echo('checked="checked"');} ?> />
              <span class="lbl"></span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              发件人姓名：
            </label>
            <div class="col-sm-9">
              <input type="text" name="options[smtp_sender_name]" id="smtp_sender_name" value="{$options.smtp_sender_name|default=''}"  class="col-xs-10 col-sm-5" required/>
              <span class="help-inline col-xs-12 col-sm-7">
                <span class="middle" id="restwo"></span>
              </span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              设置发送邮箱：
            </label>
            <div class="col-sm-9">
              <input type="email" name="options[smtp_sender_email]" id="smtp_sender_email" value="{$options.smtp_sender_email|default=''}"  class="col-xs-10 col-sm-5" required/>
              <span class="help-inline col-xs-12 col-sm-7">
                <span class="middle" id="restwo"></span>
              </span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              smtp服务器的名称：
            </label>
            <div class="col-sm-9">
              <input type="text" name="options[smtp_host]" id="smtp_host" value="{$options.smtp_host|default=''}"  class="col-xs-10 col-sm-5" required/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              连接方式：
            </label>
            <div class="col-sm-9">
              <select name="options[smtp_secure]"  class="col-xs-10 col-sm-5" required>
                {foreach name="secure_list" item="name" key="value" }
                  <option value="tls" <?php if($value==$smtp_secure){echo('checked="checked"');} ?>>
                    {$name}
                  </option>
                {/foreach}
              </select>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              SMTP服务器端口：
            </label>
            <div class="col-sm-9">
              <input type="number" name="options[smtp_port]" id="smtp_port" value="{$options.smtp_port|default=''}"  class="col-xs-10 col-sm-5" required/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              设置邮箱登录名：
            </label>
            <div class="col-sm-9">
              <input type="text" name="options[smtp_login_name]" id="smtp_email" value="{$options.smtp_email|default=''}"  class="col-xs-10 col-sm-5" required/>
              <span class="help-inline col-xs-12 col-sm-7">
                <span class="middle" id="restwo"></span>
              </span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
              设置邮箱密码：
            </label>
            <div class="col-sm-9">
              <input type="password" name="options[smtp_login_password]" id="smtp_login_password" value="{$options.smtp_login_password|default=''}"  class="col-xs-10 col-sm-5" required/>
              <span class="help-inline col-xs-12 col-sm-7">
                <span class="middle" id="resthr"></span>
              </span>
            </div>
          </div>
          <div class="space-4"></div>
          <div class="clearfix form-actions">
            <div class="col-sm-offset-3 col-sm-9">
              <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                保存
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{/block}
{block name="page_js"}
  <script src="/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $("form#settings-form").validate({
      rules:{
        "options[smtp_sender_name]":{
          required: true,
          minlength: 3,
          maxlength: 60
        }, "options[smtp_sender_email]":{
          required: true,
          email: true,
          maxlength: 50
        }, "options[smtp_port]":{
          required: true
        }, "options[smtp_email]":{
          required: true,
          email: true,
          maxlength: 50
        }
      },
      messages:{
        "options[smtp_sender_name]":{
          required: "发件人姓名不能为空",
          minlength: "发件人姓名不能少于3个字符",
          maxlength: "发件人姓名不能超过60个字符"
        }, "options[smtp_sender_email]":{
          required: "发件人姓名不能为空",
          email: "发件人姓名不正确",
          maxlength: "发件人姓名不能超过50个字符"
        }, "options[smtp_port]":{
          required: "SMTP服务器端口不能为空"
        }, "options[smtp_email]":{
          required: "设置邮箱登录名不能为空",
          email: "设置邮箱登录名格式不正确",
          maxlength: "设置邮箱登录名格式不正确"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error');
        // $(element).parents('.form-group').addClass('success');
      }
    });
  </script>
{/block}